aliases:
- Obsidian Publish/Set up Google Analytics
permalink: publish/analytics
To use analytics on your Obsidian Publish site, you need a custom domain.
Before you enable analytics, make sure that your local laws and regulations allow you to track your visitors. Depending the tools you use, you may need to add a consent banner to your site.
To enable Google Analytics for your Obsidian Publish site:
To use Google Tag Manager instead of Google Analytics, use custom JavaScript to add your own scripts.
You can add most analytics services to your site via your publish.js file. Make sure to replace yourdomain.com
with your domain, and the script src
with the script from your analytics provide.
Here is an example using Plausible Analytics
var analyticsScript = document.createElement('script');
analyticsScript.defer = true;
analyticsScript.setAttribute('data-domain', 'yourdomain.com');
analyticsScript.src = 'https://plausible.io/js/plausible.js';
document.head.appendChild(analyticsScript);
The same approach can be used for Fathom Analytics. Note the change from data-domain
to data-site
— different analytics providers may have a different format for how the script should be inserted.
var fathom = analyticsScript.createElement('script');
analyticsScript.defer = true;
analyticsScript.setAttribute('data-site', 'yourdomain.com');
analyticsScript.src = 'https://cdn.usefathom.com/script.js';
document.head.appendChild(analyticsScript);
To verify that your site is using your analytics service, disable any ad-blocking browser extensions, such as uBlock Origin, that may block the tracking script from running.